// 获取玩家喜欢的歌名页面

// 关闭VSCode非必要报错
// ignore_for_file: camel_case_types, use_build_context_synchronously, non_constant_identifier_names

import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/about_page.dart';
import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/dialogs/is_most_like_me.dart';
import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/dialogs/must_say_truth.dart';
import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/dialogs/stay_with_me_1.dart';
import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/dialogs/stay_with_me_2.dart';
import 'package:crazy_mita_problem_project/pages/get_player_favourite_song_page/favourite_color_page.dart';
import 'package:crazy_mita_problem_project/utils/my_buttons/my_button_confirmed.dart';
import 'package:flutter/material.dart';

class Pages_GetPlayerFavouriteSong extends StatefulWidget {
  const Pages_GetPlayerFavouriteSong({super.key});
  @override
  State<Pages_GetPlayerFavouriteSong> createState() => _Page_GetPlayerNameState();
}

class _Page_GetPlayerNameState extends State<Pages_GetPlayerFavouriteSong> with TickerProviderStateMixin{
  // 该文本控制器用于存储玩家最喜欢听的歌
  TextEditingController textcontroller_favourite_song=TextEditingController();  
  // 该变量用于检查玩家是否按完了这4个对话框
  bool is_press_compeleted=false;
  @override
  void initState ()    // 覆写父类构造函数
    {
      super.initState();
      // 等initState初始化完再显示对话框
      Future.delayed(Duration(milliseconds: 150)).then((_){
        showStartDialog();
      });
    }
  // 显示"一定要说真话哦"对话框
  void showStartDialog ()
    {
      showDialog(
        barrierDismissible: false, // 设置为false，禁止通过点击对话框外的屏幕内容来关闭对话框
        context: context, 
        builder: (context) {
          return Dialog_MustSayTruth();
        }
      ).then((_){    // 对话框1显示完,延迟750ms后显示下一个
        Future.delayed(Duration(milliseconds: 600)).then((_){
          showDialog(
            barrierDismissible: false, // 设置为false，禁止通过点击对话框外的屏幕内容来关闭对话框
            context: context, 
            builder: (context)
              {
                return Dialog_isMostLikeMe();
              }
          ).then((_){     // 对话框2显示完显示对话框3
            Future.delayed(Duration(milliseconds: 600)).then((_){
              showDialog(
                barrierDismissible: false, // 设置为false，禁止通过点击对话框外的屏幕内容来关闭对话框
                context: context, 
                builder: (context)
                  {
                    return Dialog_stayWithMe_First();
                  }
              ).then((_){    // 对话框3显示完显示对话框4
                Future.delayed(Duration(milliseconds: 600)).then((_){
                  showDialog(
                    barrierDismissible: false, // 设置为false，禁止通过点击对话框外的屏幕内容来关闭对话框
                    context: context, 
                    builder: (context){
                      return Dialog_stayWithMe_Second();
                    },
                  ).then((_){
                    // 当玩家4个对话框都按完了之后调整监控变量为真
                    setState(() {
                      is_press_compeleted=true;
                    });
                  });
                });
              });
            });
          });
        });
      });
    }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.purple.shade50,
      floatingActionButton: Padding(     // 设置右下角的增加符号
        padding: const EdgeInsets.only(bottom: 15.0,right: 15.0),
        child: IconButton(
          onPressed: (){
            Navigator.push(
              context, 
              MaterialPageRoute(
                builder: (context){
                  return Pages_AboutProgram();
                },
              ),
            );
          }, 
          icon:Icon(Icons.info_outline),
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              height: 450,
              width: 750,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20),
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey.shade300.withValues(), // 阴影颜色
                    spreadRadius: 3, // 阴影扩散半径
                    blurRadius: 3, // 阴影模糊半径
                    offset: Offset(0, 1), // 阴影偏移量
                  ),
                ],
              ),
              child: Padding(
                padding: const EdgeInsets.only(left:100,right: 100),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      "最喜欢的歌是什么?",
                      style: TextStyle(
                        fontSize: 30,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    const SizedBox(height: 40,),
                    TextField(
                      controller: textcontroller_favourite_song,
                      style: TextStyle(
                        fontSize: 20,
                      ),
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.symmetric(horizontal: 25,vertical: 20),   // 设置内容上下边距
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12),    // 设置输入框总圆角大小
                        ),
                        enabledBorder: OutlineInputBorder(    // 设置输入框非聚焦时的显示状态
                          borderRadius: BorderRadius.circular(12), // 设置圆角
                          borderSide: BorderSide(
                            color: Colors.grey.shade300, // 非聚焦时的边框颜色
                            width: 2.0, // 非聚焦时的边框宽度
                          ),
                        ),
                        labelText: "请输入你的答案...",
                        labelStyle: TextStyle(   // 设置提示文本文字样式
                          fontSize: 20,
                        ),
                      ),
                    ),
                    const SizedBox(height: 60,),    // 设置控件间适当距离
                    SizedBox(
                      height: 60,
                      width: 550,
                      child: MyButton_Confirmed(
                        text: "下一个", 
                        onPressed: (){
                          if (is_press_compeleted && textcontroller_favourite_song.text.isNotEmpty)
                            {
                              Navigator.push(
                                context,
                                MaterialPageRoute(
                                  builder: (context)=>Pages_GetPlayerFavouriteColor(),
                                ),
                              );
                            }
                        },
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
